/*
 * =====================================================================================
 *
 *       Filename:  a.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  04/11/08 13:47:23 CST
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:   (), 
 *        Company:  
 *
 * =====================================================================================
 */
#include "thread.h"


class A : public Thread
{
public:
    A(int e) {this->e = e;};

protected:
    virtual void run(void* arg)
    {
	sleepMills(5000);
	thread_entry(e);
    }

    void thread_entry(int e)
    {
	for(int i = 0; i < 10; i ++)
	{
	    printf("this is %d time class A e: %d \n", i, e);
	    sleepMills(500);
	}
    }
private:
    int e;
};

class C : public Thread
{
public:
    C(void* arg) : Thread( arg) {};

protected:
    virtual void run(void* arg)
    {
	thread_entry(arg);
    }

    void thread_entry(void* arg)
    {
	for(int i = 0; i < 10; i ++)
	{
	    printf("this is %d time class C arg: %d \n", i, arg);
	    sleepMills(1000);
	}
    }

};

class B {
public:
    B(){ t = new bt(this); t->start();};
    Thread * getThread(){return t;}
private:
    void print(Thread * t){ if(t == this->t ) printf("the same thread\n"); else printf("not the same\n");printf("this is B print\n");}
    class bt : public Thread {
    public:
	bt(B* b){this->b = b;}
    protected:
	virtual void run(void* arg) {
	    b->print(this);
	}
    private:
	B* b;
    };
    Thread * t;
};

int main()
{
    Thread* c = new C((void*)50);
    Thread* a = new A(20);
    a->start();
    c->start();
    B b;
    if(b.getThread() == c)
	printf("b == c\n");
    else
	printf("b != c\n");
    //sleep(12);
    a->join();
    c->join();
    return 0 ;
}
